/**
 * Created by kevin on 16/8/16.
 */
var eosi = window.eosi || {};
this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = this.eosi.fotile || {};
//this.eosi.fotile = function(name) {
//    this.name = name;
//};

(function (window) {
    // the application
    function Fotiletextafter(master) {
        this.Container_constructor();
        this.version = master.version;
        this.init(master);
    }
    var p = createjs.extend(Fotiletextafter, createjs.Container);

    // public methods:
    p.init = function (master) {
        this.fotile = master;
        console.log("I'm Master wait!!!");
        this.loadFirsrMaster();
    }

    //UI
    p.setupUI = function (){


    }

    //加载wait
    p.loadFirsrMaster = function (){
        var wait = this;
        var load=[
            {src:"static/master/wait/bg.png",id:"bg"},
            {src:"static/master/text/g_1.png",id:"g_1"},
            {src:"static/master/text/g_2.png",id:"g_2"},
            {src:"static/master/text/g_3.png",id:"g_3"},
            {src:"static/master/text/g_4.png",id:"g_4"},
            {src:"static/master/text/g_5.png",id:"g_5"},
            {src:"static/master/text/g_6.png",id:"g_6"},
            {src:"static/master/text_after/img1.png",id:"img1"},
            {src:"static/master/text_after/img2.png",id:"img2"},
            {src:"static/master/index/cloud1.png",id:"cloud1"},
            {src:"static/master/index/cloud2.png",id:"cloud2"},

            {src:"static/master/intro/hua2.png",id:"img3"},

            {src:"static/master/intro/hua3.png",id:"hua3"},]
        Fotileloader = new eosi.fotile.Fotileloader(this.fotile,load,function(){
            wait.setupLoaderUI();
        },1);
        container.addChild(Fotileloader);
        p.setupLoaderUI = function (){
            _this=this;
            var bg = new createjs.Bitmap(this.fotile.master_UILoader.getResult("bg"));
            var hua3 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("hua3"));
            var g_1 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_1"));
            var g_2 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_2"));
            var g_3 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_3"));
            var g_4 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_4"));
            var g_5 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_5"));
            var g_6 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("g_6"));
            var img1= new createjs.Bitmap(this.fotile.master_UILoader.getResult("img1"));
            var img2 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("img2"));
            var img3 =new createjs.Bitmap(this.fotile.master_UILoader.getResult("img3"));
            var cloud1 = new createjs.Bitmap(this.fotile.master_UILoader.getResult("cloud1"));
            var cloud2 =new createjs.Bitmap(this.fotile.master_UILoader.getResult("cloud2"));

            var v_w = bg.getBounds().width;
            var v_h = bg.getBounds().height;
            var w = this.fotile.getWidth();
            var h = this.fotile.getHeight();
            var ratio_y = h/v_h;
            var ratio_x =  w/v_w;
            bg.setTransform(0,0,ratio_x,ratio_y);
            bg.x=0;
            bg.y=0;

            g_1.setTransform(0,0,ratio_x,ratio_x);
            g_1.x = this.fotile.getWidth()/2-g_1.getBounds().width*ratio_x/2;
            g_1.y = (this.fotile.getHeight()/3.3)-(g_1.getBounds().height*ratio_x/2);
            g_1.alpha = 0;
            createjs.Tween.get(g_1)
                .wait(1000)
                .to({alpha:1}, 500, createjs.Ease.linear);
            
            g_2.setTransform(0,0,ratio_x,ratio_x);
            g_2.x = this.fotile.getWidth()/2-g_2.getBounds().width*ratio_x/2;
            g_2.y = (this.fotile.getHeight()/2.8)-(g_2.getBounds().height*ratio_x/2);
            g_2.alpha = 0;
            createjs.Tween.get(g_2)
                .wait(2000)
                .to({alpha:1}, 500, createjs.Ease.linear);

            g_3.setTransform(0,0,ratio_x,ratio_x);
            g_3.x = this.fotile.getWidth()/2-g_3.getBounds().width*ratio_x/2;
            g_3.y = (this.fotile.getHeight()/2.45)-(g_3.getBounds().height*ratio_x/2);
            g_3.alpha = 0;
            createjs.Tween.get(g_3)
                .wait(3000)
                .to({alpha:1}, 500, createjs.Ease.linear);

            g_4.setTransform(0,0,ratio_x,ratio_x);
            g_4.x = this.fotile.getWidth()/2-g_4.getBounds().width*ratio_x/2;
            g_4.y = (this.fotile.getHeight()/2.15)-(g_4.getBounds().height*ratio_x/2);
            g_4.alpha = 0;
            createjs.Tween.get(g_4)
                .wait(4000)
                .to({alpha:1}, 500, createjs.Ease.linear);

            g_5.setTransform(0, 0, ratio_x , ratio_x );
            g_5.x = this.fotile.getWidth()/2-g_5.getBounds().width*ratio_x/2;
            g_5.y = (this.fotile.getHeight()/1.9)-(g_5.getBounds().height*ratio_x/2);
            g_5.alpha = 0;
            createjs.Tween.get(g_5)
                .wait(5000)
                .to({alpha:1}, 500, createjs.Ease.linear);
            g_6.setTransform(0,0,ratio_x,ratio_x);
            g_6.x = this.fotile.getWidth()/2-g_6.getBounds().width*ratio_x/2;
            g_6.y = (this.fotile.getHeight()/1.7)-(g_6.getBounds().height*ratio_x/2);
            g_6.alpha = 0;
            createjs.Tween.get(g_6)
                .wait(6000)
                .to({alpha:1}, 500, createjs.Ease.linear);

            hua3.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            hua3.x =0;
            hua3.y = (this.fotile.getHeight())-(hua3.getBounds().height*ratio_x*1.1);
            hua3.alpha = 1;

            img1.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            img1.x =this.fotile.getWidth()*0.8;
            img1.y = 0;
            img1.alpha = 1;

            img2.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            img2.x =this.fotile.getWidth()*0.2;
            img2.y = (this.fotile.getHeight()*0.2)-(img2.getBounds().height*ratio_x*1.1)/2;
            img2.alpha = 1;

            cloud2.setTransform(0,0,ratio_x*0.8,ratio_x*0.8);
            cloud2.x =0;
            cloud2.y = (this.fotile.getHeight()*0.2)-(cloud2.getBounds().height*ratio_x*0.8)/2;
            cloud2.alpha = 1;

            cloud1.setTransform(0,0,ratio_x*0.8,ratio_x*0.8);
            cloud1.x =this.fotile.getWidth()-(cloud2.getBounds().width)*ratio_x*0.8;
            cloud1.y = (this.fotile.getHeight()*0.7)-(cloud1.getBounds().height*ratio_x*0.8)/2;
            cloud1.alpha = 1;

            img3.setTransform(0,0,ratio_x*1.1,ratio_x*1.1);
            img3.x =this.fotile.getWidth()*0.7;
            img3.y = (this.fotile.getHeight()*0.7)-(img2.getBounds().height*ratio_x*1.1)/2;
            img3.alpha = 1;

            this.addChild(bg);
            this.addChild(hua3);
            // this.clearLoading=function (){
            //     this.removeChild(bg);
            //     this.removeChild(text_box_bg);
            //     this.removeChild(logo);
            this.addChild(g_1);
            this.addChild(g_2);
            this.addChild(g_3);
            this.addChild(g_4);
            this.addChild(g_5);
            this.addChild(g_6);

            this.addChild(img1);
            this.addChild(img3);
            this.addChild(img2);
            this.addChild(cloud1);
            this.addChild(cloud2);
            
            stage.update();
            //     this.removeChild(bn);
            //     this.removeChild(downarrow);

            //     document.getElementById("canvas").removeEventListener("click",clickPlayBn);
            //     container.removeChild(master);
        }

    }
    // add MyApp to myNameSpace
    window.eosi.fotile.Fotiletextafter = createjs.promote(Fotiletextafter, "Container");
}(window));
